package com.dong.rabbitmq.direct;

import com.dong.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

import static com.dong.rabbitmq.common.Constant.*;

/**
 * @author dongjian
 *
 * Direct模式生产者
 */
public class DirectLogsProducer {

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtil.getChannel();
        channel.exchangeDeclare(DIRECT_EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String msg = scanner.next();
            // 修改routingKey，发送给不同队列消息
            channel.basicPublish(DIRECT_EXCHANGE_NAME, "error", null, msg.getBytes("UTF-8"));
            System.out.println("生产者发出消息====>" + msg);
        }
    }
}
